package com.moefor.clover.model;

import java.util.Date;
import java.util.Set;

import javax.persistence.*;

import com.moefor.clover.model.element.Picture;
import com.moefor.clover.model.enums.StateOfGoods;

@Entity
public class Goods extends BaseEntity{
	@Column(nullable = false)
	private String name;
	
	@JoinColumn(nullable = false)
	@ManyToOne(cascade = {CascadeType.ALL})
	private User owner;
	
	@ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
	private Set<Market> marketItems;
	
	@Column(nullable = false)
	private Float price;
	
	@Column(nullable = false)
	private Date date;

	@Column(nullable = false)
	private String introduction;
	
	@Column
	@OneToMany(mappedBy = "goods", fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
	private Set<Order> orderItems;
	
	public Set<Order> getOrderItems() {
		return orderItems;
	}

	public void setOrderItems(Set<Order> orderItems) {
		this.orderItems = orderItems;
	}

	@Column(nullable = false)
	@Enumerated(EnumType.ORDINAL)
	private StateOfGoods state;
	
	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	//@JsonBackReference
	@OneToMany(mappedBy = "goods")
	private Set<Comment> commentItems;
	
	@ElementCollection(fetch = FetchType.EAGER)
	@JoinTable(name = "goods_pic_coll", joinColumns=@JoinColumn(name="goods_id"))
	private Set<Picture> picItems;

	public Set<Picture> getPicItems() {
		return picItems;
	}

	public void setPicItems(Set<Picture> picItems) {
		this.picItems = picItems;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Set<Market> getMarketItems() {
		return marketItems;
	}

	public void setMarketItems(Set<Market> marketItems) {
		this.marketItems = marketItems;
	}
	
	public Float getPrice() {
		return price;
	}

	public void setPrice(Float price) {
		this.price = price;
	}
	
	public User getOwner() {
		return owner;
	}

	public void setOwner(User owner) {
		this.owner = owner;
	}
	public String getIntroduction() {
		return introduction;
	}

	public void setIntroduction(String introduction) {
		this.introduction = introduction;
	}

	

	public StateOfGoods getState() {
		return state;
	}

	public void setState(StateOfGoods state) {
		this.state = state;
	}


	public Set<Comment> getCommentItems() {
		return commentItems;
	}

	public void setCommentItems(Set<Comment> commentItems) {
		this.commentItems = commentItems;
	}
}